'''
Created on 29/09/2014

@author: David
'''
import unittest
from Sodev.kernel import Kernel
from Sodev.program import Program
from Sodev.Instr import Instr
from Sodev.scheduler import Scheduler
from Sodev.cpu import Cpu
from Sodev.memoryAdmin import Memoryadmin
from Sodev.clock import Clock
from Sodev.irqKill import IRQKill
from Sodev.IOInstr import IOInstr
from Sodev.IO import IO
from Sodev.CPUInstr import CPUInstr
from Sodev.schedulerQueueP import SchedulerQueueP
from Sodev.handlerPCB import HandlerPCB
from Sodev.SchedulerRoundRobin import SchedulerRoundRobin
from Sodev.CompactacionParaArriba import CompactacionParaArriba
from Sodev.CompactacionParaAbajo import CompactacionParaAbajo
from Sodev.Block import Block
from Sodev.asignacionContinua import AsignacionContinua
from Sodev.firstFit import FirstFit
from Sodev.fileSystem import FileSystem
from Sodev.hardDrive import Harddrive
from Sodev.file import File
from Sodev.folder import Folder
from Sodev.bestFit import BestFit
from Sodev.worstFit import WorstFit
from Sodev.paginacion import Paginacion

class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        
        bf = BestFit()
        ff = FirstFit()
        wf = WorstFit()
               
        cpa = CompactacionParaArriba()
        cpd = CompactacionParaAbajo()
        mem= Memoryadmin()
        mem.setAsignacionContinua(cpd, bf)
        clock = Clock(None)
        
        handlerPCB = HandlerPCB(None)
        
        cpu = Cpu(mem,clock, handlerPCB)
        
        clock.setCpu(cpu)
        
        sfifo = Scheduler(cpu)
        sQueueP = SchedulerQueueP(cpu) 
        sRR= SchedulerRoundRobin(cpu)
        
        tkernel = Kernel(sfifo)
        tkernel.memoryadmin = mem
        
        handlerPCB.kernel = tkernel
        handlerPCB.iniciarHandlers()

        
        self.comKernel = tkernel
        self.cpu = cpu
        self.adminMem = mem
        self.kernel = tkernel
        
        

    def test_ttt(self):
        mem = self.adminMem.memory
        mem.write(0, IOInstr())
        mem.write(1, IOInstr())
        mem.write(4, IOInstr())
        mem.write(5, IOInstr())
        block1u = Block()
        block1u.initPos = 0
        block1u.endPos = 1
        block1u.pid = 9
        block2u = Block()
        block2u.initPos = 4
        block2u.endPos = 5
        block2u.pid = 11
        self.adminMem.assignationModule.usedBlocks.append(block1u)
        self.adminMem.assignationModule.usedBlocks.append(block2u)
        block1n = Block()
        block1n.initPos = 2
        block1n.endPos = 3
        block2n = Block()
        block2n.initPos = 6
        block2n.endPos = 9
        self.adminMem.assignationModule.freeBlocks = []
        self.adminMem.assignationModule.freeBlocks.append(block1n)
        self.adminMem.assignationModule.freeBlocks.append(block2n)
        
        tprograma=Program("test")
        instruccion1 = CPUInstr()
        instruccion2 = IOInstr()
        tprograma.addInstr(instruccion1)
        tprograma.addInstr(instruccion2)
        self.kernel.writeProgramOnHD("root/",tprograma)
        self.kernel.runII("/test")
        
        print(mem.read(0))
        print(mem.read(1))
        print(mem.read(2))
        print(mem.read(3))
        print(mem.read(4))
        print(mem.read(5))
        print(mem.read(6))
        print(mem.read(7))
        print(mem.read(8))
        print(mem.read(9))
        
      
if __name__ == "__main__":
    unittest.main()